<script setup lang="ts">
/* @jsxImportSource vue */
import { storeToRefs } from 'pinia'
import { computed, h, inject, ref } from 'vue'
// import katex, {KatexOptions} from 'katex'
import * as katex from 'katex'
import type { KatexOptions } from 'katex'
import { NButton, NConfigProvider, NEquation, NInput, NSelect } from 'naive-ui'
import { useSgesCStore } from './storeSgesCalC.ts'
import { utils } from 'yklib'

const { base_data, generateOptions, ropeData } = utils;
const props = defineProps<{ // withDefaults给defineProps中的参数绑定默认值
  create3D?: Function // 创建3D模型的回调函数
}>()

const store = useSgesCStore()
const {
  calInfo, DiameterPulley, radiusPulleyGroove, widthSinglePulley, widthPulleySideWall,
  priceRope,
  priceShaft, bPulleyOuter,
  priceRopes,
  priceShafts,
  massShaftTotal,
  massTotalShaftAndRopes,
  lengthL0Shaft,
  massL0Shaft,
  numRopeLaps,
  numLapsPerLayer,
  numRopeLayers,
  lengthLShaft,
  numLShaft,
  speedRotateReel,
  massLShaft,
  massRopes,
  massRopePer100,
  massSingleRope,
  speedRatio2,
  ropeTripTimes,
  lengthRopeGuidance,
  lengthRopeTrips,
  lengthRope,
  velRope,
  diameterReel,
  lengthReel,
  girthReel,
  ropeCoreClass,
  ropeCoreClasses,
  ropeClass,
  ropeClasses,
  ropeStrands,
  ropeStrand,
  lvlRope,
  forceRopeBreak,
  safetyRatioRope,
  diameterRope_mm,
  forceRope,
  numRopePerBlock,
  numPulleyPerRope,
  powerBlocksSim,
  chargePower,
  disChaPower,
  chargePowerSingleGen_MW,
  disChaPowerSingleGen_MW,
  chargePowerSingleGen,
  disChaPowerSingleGen,
  powerSingleBlock,
  powerSingleBlock_MW,
  speedRotateGen,
  velWeight_m_h,
  velWeight_m_s,
  proSim,
  timeSinglePass,
  areaCoe,
  areaTotalSta,
  areaTotalTower,
  widthPerGenGroup,
  lengthPerGenGroup,
  areaPerGenGroup,
  areaControlRoom,
  gapReel,
  distancePillarWeight,
  totalMassAssistance_t,
  totalMassAssistance,
  totalWeightAssistance,
  pillar_set,
  diameter_pillar,
  etaCharge_100,
  etaDischarge_100,
  etaSystem_100,
  capChargeTotalSta,
  capDischargeTotalSta,
  powerChargeTotalSta,
  totalChargeTime,
  cal_power,
  vibrant_para,
  vibrant_option,
  heightTower,
  density,
  lengthBlock,
  widthBlock,
  heightBlock,
  etaSystem,
  volumeBlock,
  massBlock,
  etaCharge,
  etaDischarge,
  totalBlocksNum,
  totalMassBlocks,
  totalGravityEnergy,
  g,
  girthReelInner,
  totalGravityEnergy_MJ,
  weightBlock,
  widthGenRegion,
  numOfGens,
  numOfCellsPerSide,
  numOfCellsPerGen,
  numGensSim,
  speedHShaft,
  torqueHShaft,
  dHShaft_mm,
  speedLShaft,
  powerLShaft,
  torqueLShaft,
  dLShaft_mm,
  lengthHShaft,
  massHShaft,
  numHShaft,
  massHShafts,
  massLShafts,
  numL0Shaft,
  massL0Shafts, lengthPadding, widthPadding,
  powerHShaft, d1PulleySideWall,
  widthForPulley, diameterReelSideWall, widthReelSideWall, diameterReelSideBrake,
  accelerationC1, timeC1, distanceC1, forceC1, ratioC1, torqueLShaftMax,
  timeC2, accelerationC2, distanceC2, numGensPerGroup,
  gapBlockPulley, gapPulleys, thickPulleyLayer, heightPulleyLayer, thickGenLayer, heightGenLayer, thickRoof
} = storeToRefs(store)


const show_pillar_settings = ref(false)
const show_area_settings = ref(false)

type rowType = {
  key: number,
  item: string,
  symbol: string,
  unit: string,
  formula: string,
  val: number | string,
  bak: string
}

const editableVal = [  // 可以编辑的数值行
  // "钢丝绳安全系数", "动滑轮数量", "单个重物钢丝绳数量","发电机转速",
  // "螺伞齿轮箱变速比",
  '重物块与壁面预留距离', '发电机预留宽度', '集控室占地面积',
  '面积裕度系数', '钢丝绳单价', '屋顶厚度', '静滑轮层厚度', '发电机层地面厚度', '轴单价', '重物块和滑轮间隙'

]

const editableSel = [  // 可以编辑的下拉列表行
  '钢丝绳级', '钢丝绳芯类型', '钢丝绳类型', '钢丝绳股型号'
]

const sepRow = [
  '发电机计算', '轴的重量计算', '卷筒计算', '价格计算', '储能塔布局', '钢丝绳计算', '变速箱计算', '加减速计算'
]

const columns = () => {
  return [

    {
      title: '项目', key: 'item',
      render(row: rowType) {
        if (row.item === '重物有效提升高度') {
          return h('span', { style: 'color: red' }, row.item)
        } else {
          return h('span', {}, row.item)
        }
      }
    },
    {
      title: "符号", key: 'symbol',
      render(row: rowType) {
        return h(NConfigProvider, { katex: katex as any },
          () => h(NEquation, { value: row.symbol, katexOptions: { output: "mathml" } }))
      }
    },
    {
      title: '单位', key: 'unit'
    },
    {
      title: '公式', key: 'formula',
      render(row: rowType) {
        if (row.item === '承重柱直径') {
          return h(NButton, {
            onclick: () => {
              show_pillar_settings.value = true
            }
          }, () => {
            return '承重柱设置'
          })
        } else if (row.item === '储能塔总占地面积') {
          return h(NButton, {
            onclick: () => {
              show_area_settings.value = true
            }
          }, () => {
            return '设置'
          })
        } else {
          return h(NConfigProvider, { katex: katex } as any,
            () => h(NEquation, { value: row.formula, katexOptions: { output: 'mathml' } }))
        }
      }
    },
    {
      title: '数值', key: 'val',
      render(row: rowType, index: number) {
        if (row.item === '重物有效提升高度') {
          return h('span', { style: 'color: red' }, row.val)
        } else if (editableVal.includes(row.item)) {
          return h(NInput, {
            value: String(row.val),
            style: 'background-color: lightgreen; padding-top: 0px; margin: 0px',
            onUpdateValue(v: string) {
              // @ts-ignore
              row.val = v // 此处不能加Number(v)，否则无法输入小数
            }
          })
        } else if (editableSel.includes(row.item)) {
          let options
          if (row.item === '钢丝绳级') {
            options = ropeData.ropeLevel
          } else if (row.item === '钢丝绳类型') {
            options = Object.keys(ropeData.ropeType)
          } else if (row.item === '钢丝绳股型号') {
            let _ = ropeData.ropeType[ropeClass.value]
            options = Object.keys(_)
          } else {
            options = ropeData.ropeCoreClass
          }

          return h('select', {
            onInput: (e: Event) => {
              row.val = (<HTMLSelectElement>e.target).value
            },
            class: 's1',
            value: row.val,
            style: 'width: 150px; height: 25px; background-color: lightgreen'
          }, generateOptions(options).map(option =>
            h('option', {
              value: option.value,
              style: 'padding: 1px; margin: 1px; background-color: lightgreen'
            }, option.label)
          ))
        } else {
          return h('span', {}, row.val)
        }
      }
    },
    {
      title: '备注', key: 'bak',
      render(row: rowType) {
        if (row.item === '承重柱直径') {
          return h('div', {}, [
            h('div', {}, row.bak),
            h('a', {
              href: 'https://www.mohurd.gov.cn/gongkai/zhengce/zhengcefilelib/202107/20210715_761192.html',
              target: '_blank'
            }, 'GB 55001《工程结构通用规范》'),
            h('div', {}, ''),
            h('a', {
              href: 'https://www.mohurd.gov.cn/gongkai/zhengce/zhengcefilelib/202110/20211013_762454.html',
              target: '_blank'
            }, 'GB 55008 《混凝土结构通用规范》'),
            h('div', {}, ''),
            h('a', {
              href: 'https://www.mohurd.gov.cn/gongkai/zhengce/zhengcefilelib/202111/20211130_763200.html',
              target: '_blank'
            }, 'GB/T 51446 《钢管混凝土混合结构技术标准》')
          ])
        } else {
          return h('span', {}, row.bak)
        }
      }
    }

  ]
}

const tableData = ref([
  {
    key: 0,
    item: '储能容量',
    symbol: 'Cap_t',
    unit: 'MWh',
    formula: 'from\\ design',
    val: capChargeTotalSta, // 不能带.value，否则会失去响应性
    bak: '设计边界条件'
  },
  {
    key: 1,
    item: '放电容量',
    symbol: 'Cap_{td}',
    unit: 'MWh',
    formula: '=Cap_t/eta_s',
    val: capDischargeTotalSta,
    bak: ''
  },
  {
    key: 1,
    item: '储能效率',
    symbol: '\\eta_s',
    unit: '%',
    formula: 'from\\ design',
    val: etaSystem_100,
    bak: '电动发电机出口测量',
    children: [
      {
        key: 2,
        item: '充电效率',
        symbol: '\\eta_c',
        unit: '%',
        formula: '=sqrt(eta_s)',
        val: etaCharge_100,
        bak: '电动发电机出口测量'
      },
      {
        key: 3,
        item: '释能效率',
        symbol: '\\eta_d',
        unit: '%',
        formula: '=\\sqrt{\\eta_s}',
        val: etaDischarge_100,
        bak: '电动发电机出口测量'
      }
    ]
  },


  {
    key: 4,
    item: '重物有效提升高度',
    symbol: 'H_T',
    unit: 'm',
    formula: '=\\frac{1000000 M_s}{Weight_s}',
    val: heightTower
  },
  {
    key: 4,
    item: '重物长',
    symbol: 'H_T',
    unit: 'm',
    formula: 'from\\ design',
    val: lengthBlock
  },
  {
    key: 4,
    item: '重物宽',
    symbol: 'H_T',
    unit: 'm',
    formula: 'from\\ design',
    val: widthBlock
  },
  {
    key: 4,
    item: '重物高',
    symbol: 'H_T',
    unit: 'm',
    formula: 'from\\ design',
    val: heightBlock
  },
  {
    key: 5,
    item: '单个重物体积',
    symbol: 'Vol_s',
    unit: 'm3',
    formula: '=L_s\\times W_s\\times H_s',
    val: volumeBlock
  },
  {
    key: 5,
    item: '重物密度',
    symbol: 'Density_s',
    unit: 'kg/m3',
    formula: '=L_s\\times W_s\\times H_s',
    val: density
  },
  {
    key: 6,
    item: '单个重物质量',
    symbol: 'M_s',
    unit: 'kg',
    formula: '=Vol_s\\times D_s',
    val: massBlock
  },
  {
    item: '单个重物重力',
    symbol: 'Weight_s',
    unit: 'N',
    formula: '=M_sg',
    val: weightBlock
  },

  {
    item: '重物总数量',
    symbol: 'n_w',
    unit: '个',
    formula: '=N_tN_gN_c',
    val: totalBlocksNum
  },
  {
    key: 6,
    item: '重物总质量',
    symbol: 'M_t',
    unit: 'kg',
    formula: '=M_s\\times n_w',
    val: totalMassBlocks
  },
  {
    key: 7,
    item: '重物可储存势能',
    symbol: 'GE_t', // gravity energy _ total
    unit: 'MJ',
    formula: '=Cap_t/eta_c',
    val: totalGravityEnergy_MJ
  }, {},
  {
    key: 6,
    item: '发电机总数量',
    symbol: 'N_t',
    unit: '个',
    formula: '=from\\ design',
    val: numOfGens
  },
  {
    key: 6,
    item: '每组重物数量',
    symbol: 'N_g',
    unit: '个',
    formula: '=from\\ design',
    val: numOfCellsPerSide
  },
  {
    key: 6,
    item: '每个发电机拖动的重物数量',
    symbol: 'N_c',
    unit: '个',
    formula: '=from\\ design',
    val: numOfCellsPerGen
  },

  {
    key: 6,
    item: '重物块总数',
    symbol: 'n_{wt}',
    unit: '个',
    formula: '=r_{weight} \\times c_{weight}',
    val: totalBlocksNum
  },

  {},
  {
    item: '承重柱直径',
    symbol: 'D_p',
    unit: 'm',
    formula: '',
    val: diameter_pillar,
    bak: '参考标准',
    children: [
      {
        item: '钢材材质',
        val: pillar_set.value.steelType
      },
      {
        item: '混凝土型号',
        val: pillar_set.value.concreteType
      },
      {
        item: '含钢率',
        symbol: '\\alpha',
        val: pillar_set.value.steelRatio
      }, {
        item: '钢材密度',
        val: pillar_set.value.steelDensity
      }
    ]
  },
  {
    key: 6,
    item: '电站需求总面积',
    symbol: 'A_{room}',
    unit: 'm2',
    formula: '=A_{room}+A_kA_{towers}',
    val: areaTotalSta,
    children: [
      {
        item: '重物块与壁面预留距离',
        symbol: 'd_{pw}',
        unit: 'm',
        formula: '',
        val: distancePillarWeight
      },
      {
        item: '发电机预留宽度',
        symbol: 'W_{gen}',
        unit: 'm',
        formula: '',
        val: widthGenRegion
      },
      {
        key: 6,
        item: '单发电机塔组长度',
        symbol: 'L_{tower}',
        unit: 'm',
        formula: '=c_{weight}(L_{weight}+2d_{pw})',
        val: lengthPerGenGroup
      },
      {
        key: 6,
        item: '单发电机塔组宽度',
        symbol: 'L_{tower}',
        unit: 'm',
        formula: '=from\\ design',
        val: widthPerGenGroup
      },
      {
        item: '单塔组占地面积',
        symbol: 'A_{group}',
        unit: 'm^2',
        formula: '=m^2',
        val: areaPerGenGroup
      },
      {
        key: 6,
        item: '塔群总占地面积',
        symbol: 'A_{towers}',
        unit: 'm2',
        formula: '=L_{tower}N_t',
        val: areaTotalTower
      },
      {
        key: 6,
        item: '集控室占地面积',
        symbol: 'A_{room}',
        unit: 'm2',
        formula: '=from\\ design',
        val: areaControlRoom
      },
      {
        item: '面积裕度系数',
        symbol: 'A_k',
        unit: '',
        formula: '',
        val: areaCoe,
        children: []
      }
    ]
  },

  {},

  {
    item: '总充电时间',
    symbol: 't_c',
    unit: 'h',
    val: totalChargeTime
  },
  {
    item: '设计同时运行重物占比',
    symbol: 't_d',
    unit: '',
    val: proSim
  },
  {
    item: '同时运行发电机数量',
    symbol: 't_d',
    unit: '',
    val: numGensSim
  },
  {
    item: '单程运行时间',
    symbol: 't_{sp}',
    unit: 'h',
    val: timeSinglePass
  },
  {
    item: '额定重物运行速度',
    symbol: 'v_{bc}',
    unit: 'm/s',
    val: velWeight_m_s
  },
  {
    item: '单重物运行功率',
    symbol: 'P_{sb}',
    unit: 'MW',
    formula: '=Weight_s \\times v_{bc}/1000000',
    val: powerSingleBlock_MW
  },
  {
    item: 'THA重物运行功率',
    symbol: 'P_{sb}',
    unit: 'MW',
    formula: '=Weight_s \\times v_{bc}/1000000',
    val: computed(() => powerBlocksSim.value / 1000000)
  },
  {
    item: '发电机计算',
    bak: '双出轴'
  },
  {
    item: '发电电动机充电功率',
    symbol: 'P_gs',
    unit: 'MW',
    val: chargePowerSingleGen_MW
  },
  {
    item: '发电电动机发电功率',
    symbol: 'P_gs',
    unit: 'MW',
    val: disChaPowerSingleGen_MW
  },
  {
    item: '总充电功率',
    symbol: 'P_gs',
    unit: 'MW',
    val: computed(() => chargePower.value / 1000000)
  },
  {
    item: '总发电功率',
    symbol: 'P_gs',
    unit: 'MW',
    val: computed(() => disChaPower.value / 1000000)
  },
  {
    item: '发电机转速',
    symbol: 'S_r',
    unit: 'rpm',
    val: speedRotateGen
  },

  {
    item: '齿轮箱变比',
    symbol: 'r_{gear}',
    unit: '/',
    val: speedRatio2
  },
  {
    item: '高速轴转速',
    symbol: 'r_{gear}',
    unit: 'rpm',
    val: speedHShaft
  },
  {
    item: '高速轴功率',
    symbol: 'P_{H}',
    unit: 'MW',
    val: computed(() => powerHShaft.value / 1000000)
  },
  {
    item: '高速轴扭矩',
    symbol: 'Torque_{ms}',
    unit: 'Nm',
    val: torqueHShaft
  },
  {
    item: '高速轴直径',
    symbol: 'd_{hs}',
    unit: 'mm',
    val: dHShaft_mm
  },
  {
    item: '低速轴转速',
    symbol: 's_{ls}',
    unit: 'rpm',
    val: speedLShaft
  },


  {
    item: '低速轴功率',
    symbol: 'P_{ls}',
    unit: 'MW',
    val: computed(() => powerLShaft.value / 1000000)
  },
  {
    item: '低速轴扭矩',
    symbol: 'Torque_{ms}',
    unit: 'Nm',
    val: torqueLShaft
  },
  {
    item: '低速轴直径',
    symbol: 'd_{mhs}',
    unit: 'mm',
    val: dLShaft_mm
  },
  { item: '变速箱计算' },
  {
    item: '输入轴转速',
    symbol: 'n_{is}',
    unit: 'rpm',
    val: speedHShaft
  },
  {
    item: '输出轴转速',
    symbol: 'n_{os}',
    unit: 'rpm',
    val: speedLShaft
  },
  {
    item: '变比',
    symbol: 'n_{os}',
    unit: '/',
    val: speedRatio2
  },
  {
    item: '输入功率',
    symbol: 'p_{is}',
    unit: 'W',
    val: powerHShaft
  },
  {
    item: '输入轴扭矩',
    symbol: 't_{is}',
    unit: 'Nm',
    val: torqueHShaft
  },
  {
    item: '输出轴扭矩',
    symbol: 't_{os}',
    unit: 'Nm',
    val: torqueLShaft
  },

  { item: '钢丝绳计算' },
  {
    item: '单个重物钢丝绳数量',
    symbol: 'N_{rpb}',
    unit: '根',
    val: numRopePerBlock
  },
  {
    item: '动滑轮数量',
    symbol: 'N_{pulley}',
    unit: '个',
    val: numPulleyPerRope
  },
  {
    item: '钢丝绳安全系数',
    symbol: 'f_{rs}',
    unit: '/',
    val: safetyRatioRope
  },
  {
    item: '钢丝绳拉力',
    symbol: 'F_{rope}',
    unit: 'N',
    val: forceRope
  },
  {
    item: '钢丝绳破断拉力',
    symbol: 'F_{rb}',
    unit: 'N',
    val: forceRopeBreak
  },

  {
    item: '钢丝绳直径',
    symbol: 'd_{rope}',
    unit: 'mm',
    val: diameterRope_mm,
    bak: '轴径计算参考https://www.mechtool.cn/manual/manual_shaftdesignmanual1stedition1993.html 第56页',
    children: [
      {
        item: '钢丝绳级',
        symbol: 'Lvl_{r}',
        unit: '',
        formula: '',
        val: lvlRope
      },
      {
        item: '钢丝绳类型',
        symbol: 'Lvl_{r}',
        unit: '',
        formula: '',
        val: ropeClass
      },
      {
        item: '钢丝绳股型号',
        symbol: 'Lvl_{r}',
        unit: '',
        formula: '',
        val: ropeStrand
      },
      {
        item: '钢丝绳芯类型',
        symbol: 'Lvl_{r}',
        unit: '',
        formula: '',
        val: ropeCoreClass
      }
    ]
  },

  {
    item: '钢丝绳导向段长度',
    symbol: 'L_{g}',
    unit: '',
    formula: '2\\times\\frac{L_{reel}}{2tan1.5°}',
    val: lengthRopeGuidance
  },
  {
    item: '钢丝绳总长度',
    symbol: 'L_{rope}',
    unit: '',
    formula: '2n_{pully}H_{T}+L_g',
    val: lengthRope
  },
  {
    item: '钢丝绳参考重量',
    symbol: 'M_{rr}',
    unit: 'kg/100m',
    formula: 'calculate\\ value',
    val: massRopePer100
  },
  {
    item: '单根钢丝绳重量',
    symbol: 'M_{r1}',
    unit: 'kg/根',
    formula: 'M_{rr}L_{rope}',
    val: massSingleRope
  },
  {
    item: '滑轮直径',
    symbol: 'D_{pulley}',
    unit: 'm',
    formula: '',
    val: DiameterPulley,
    bak: '参考JB/T 9005.2-1999《起重机用铸造滑轮直径的选用系列与匹配》\nGB/T 27546-2011 起重机械 滑轮'
  },
  {
    item: '单滑轮宽度',
    symbol: 'W_{pulley}',
    unit: 'm',
    formula: '=f(D_{pulley})',
    val: widthSinglePulley,
    bak: '计算参考https://yunqi.qq.com/read/29976671/27《机械设计手册 第6版》'
  },
  {
    item: '滑轮挡边宽度',
    symbol: 'W_{side}',
    unit: 'm',
    formula: '=f(0.5D_{pulley})',
    val: widthPulleySideWall,
    bak: ''
  },
  {
    item: '滑轮绳槽口宽度b',
    symbol: 'b_{pulley}',
    unit: 'm',
    formula: '=f(D_{pulley})',
    val: bPulleyOuter,
    bak: '计算参考https://yunqi.qq.com/read/29976671/27《机械设计手册 第6版》'
  },
  {
    item: '滑轮挡边直径',
    symbol: 'D1_{PulleySide}',
    unit: 'm',
    formula: 'design',
    val: d1PulleySideWall,
    bak: '计算参考https://yunqi.qq.com/read/29976671/27《机械设计手册 第6版》'
  },
  {
    item: '滑轮组宽度',
    symbol: 'W_{pulleys}',
    unit: 'm',
    formula: '=(2W_{side}+N_{pulleys}W_{pulley})N_{rpb}',
    val: widthForPulley,
    bak: '一个重物块上所有滑轮组的总宽度，包含隔板宽度'
  },
  {
    item: '滑轮绳槽半径',
    symbol: 'R_{groove}',
    unit: 'm',
    formula: '',
    val: radiusPulleyGroove,
    bak: '参考JB/T 9005.1-1999 起重机用铸造滑轮 绳槽断面'
  },

  {
    item: '钢丝绳数量',
    symbol: 'n_{r}',
    unit: '根',
    formula: 'n_wN_{rpb}',
    val: computed(() => numRopePerBlock.value * totalBlocksNum.value)
  },
  {
    item: '钢丝绳总重量',
    symbol: 'M_{rt}',
    unit: 'kg',
    formula: 'n_rM_{r1}',
    val: massRopes
  },

  { item: '轴的重量计算' },

  {
    item: '所有轴系总质量',
    symbol: 'r_{gear}',
    unit: 't',
    val: computed(() => massShaftTotal.value / 1000)
  },
  {
    item: '高速轴长度',
    symbol: 'r_{gear}',
    unit: 'm',
    val: lengthHShaft
  },
  {
    item: '高速轴质量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massHShaft
  },
  {
    item: '高速轴数量',
    symbol: 'r_{gear}',
    unit: '个',
    val: numHShaft
  },
  {
    item: '高速轴总质量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massHShafts
  },

  {
    item: '低速轴长度',
    symbol: 'r_{gear}',
    unit: 'm',
    val: lengthLShaft
  },
  {
    item: '低速轴质量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massLShaft
  },
  {
    item: '低速轴数量',
    symbol: 'n_{mHs}',
    unit: '个',
    val: numLShaft
  },
  {
    item: '低速轴总质量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massLShafts
  },

  {
    item: '副轴连接段长度',
    symbol: 'r_{gear}',
    unit: 'm',
    val: lengthL0Shaft
  },
  {
    item: '副轴连接段重量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massL0Shaft
  },
  {
    item: '副轴连接段数量',
    symbol: 'r_{gear}',
    unit: '个',
    val: numL0Shaft
  },
  {
    item: '副轴连接段总质量',
    symbol: 'r_{gear}',
    unit: 'kg',
    val: massL0Shafts
  },


  { item: '卷筒计算' },

  {
    item: '卷筒直径',
    symbol: 'd_{reel}',
    unit: 'm',
    formula: 'from design',
    val: diameterReel
  },
  {
    item: '卷筒卷线区长度',
    symbol: 'L_{reel}',
    unit: 'm',
    formula: 'design',
    val: lengthReel
  },
  {
    item: '挡边高度(无碟刹处)',
    symbol: 'H_{rs}',
    unit: 'm',
    formula: '=d_{reel}+1.2d_{rope}n_{layers}',
    val: diameterReelSideWall
  },
  {
    item: '挡边高度(碟刹处)',
    symbol: 'H_{rsd}',
    unit: 'm',
    formula: '=H_{rs}+0.2',
    val: diameterReelSideBrake
  },
  {
    item: '卷筒挡边宽度',
    symbol: 'W_{rsd}',
    unit: 'm',
    formula: 'design',
    val: widthReelSideWall
  },
  {
    item: '卷筒周长',
    symbol: 'C_{reel}',  // circumference_reel
    unit: 'm',
    formula: '\\pi d_{reel}',
    val: girthReel
  },
  {
    item: '最内圈缠绕周长',
    symbol: 'C_{InnerRope}',  // circumference_reel
    unit: 'm',
    formula: '\\pi (d_{reel}+d_{rope})',
    val: girthReelInner
  },
  {
    item: '钢丝绳缠绕总圈数',
    symbol: 'n_{rt}', // revolutions total
    unit: '圈',
    val: numRopeLaps
  },
  {
    item: '每层可缠绕圈数',
    symbol: 'n_{rpl}', // n_{rpl} revolutions per layers
    unit: '圈',
    val: numLapsPerLayer
  },
  {
    item: '钢丝绳缠绕层数',
    symbol: 'n_{layers}',
    unit: '层',
    val: numRopeLayers
  },
  {
    item: '卷筒驱动端线速度',
    symbol: 'v_{reel}',
    unit: 'm/s',
    val: velRope
  },
  {

    item: '卷筒转速',
    symbol: 'rs_{reel}',
    unit: 'rpm',
    val: speedRotateReel
  },

  { item: '加减速计算' },

  {
    item: '储能加速过程',
    children: [
      {
        item: '加速时间',
        symbol: 't_{c1}',
        unit: 's',
        formula: 'from design',
        val: timeC1
      },
      {
        item: '加速度',
        symbol: 'a_{c1}',
        unit: 'm/s^2',
        formula: 'v/t_{c1}',
        val: accelerationC1
      },
      {
        item: '加速距离',
        symbol: 's_{c1}',
        unit: 'm',
        formula: '\\frac{1}{2}v_{bc} t_{c1}',
        val: distanceC1
      },
      {
        item: '加速额外拉力',
        symbol: 'f_{c1}',
        unit: 'm',
        formula: 'm_{weight} a_{c1}',
        val: forceC1
      },
      {
        item: '加速时变速箱输出扭矩',
        symbol: 'f_{c1}',
        unit: 'm',
        formula: 'm_{weight} a_{c1}',
        val: torqueLShaftMax
      },
      {
        item: '加速冲击力占比',
        symbol: 'f_{c1}',
        unit: 'm',
        formula: 'f_{c1}/ Weight_{s}',
        val: ratioC1
      }
    ]
  },


  {
    item: '储能减速过程',
    children: [
      {
        item: '减速时间',
        symbol: 't_{c2}',
        unit: 's',
        formula: 'v_{bc}/g',
        val: timeC2
      },
      {
        item: '减速过程中的加速度',
        symbol: 'a_{c2}',
        unit: 'm/s^2',
        formula: 'g',
        val: accelerationC2
      },
      {
        item: '减速距离',
        symbol: 's_{c1}',
        unit: 'm',
        formula: '\\frac{1}{2}v_{bc} t_{c2}',
        val: distanceC2
      }
    ]
  },

  {
    item: '储能塔布局'
  },
  {
    item: '重物块和滑轮间隙',
    symbol: 'H_{1}',
    unit: 'm',
    val: gapBlockPulley
  },

  {
    item: '动静滑轮间隙',
    symbol: 'H_{2}',
    unit: 'm',
    val: gapPulleys,
    formula: 'D_{pulley}*1.2',
    bak: '动滑轮与静滑轮层最小间隙'
  },

  {
    item: '静滑轮层厚度',
    symbol: 'H_{3}',
    unit: 'm',
    val: thickPulleyLayer,
    bak: '静滑轮层地面厚度'
  },

  {
    item: '滑轮层净高',
    symbol: 'H_{4}',
    unit: 'm',
    val: heightPulleyLayer,
    bak: '静滑轮层净高度'
  },
  {
    item: '发电机层地面厚度',
    symbol: 'H_{5}',
    unit: 'm',
    val: thickGenLayer
  },

  {
    item: '发电机层净高',
    symbol: 'H_{5}',
    unit: 'm',
    val: heightGenLayer
  },

  {
    item: '屋顶厚度',
    symbol: 'H_{6}',
    unit: 'm',
    val: thickRoof
  },
  {
    item: '屋顶X方向伸出长度',
    symbol: '',
    unit: 'm',
    val: lengthPadding
  },
  {
    item: '屋顶Y方向伸出长度',
    symbol: '',
    unit: 'm',
    val: widthPadding
  },
  {
    item: '卷筒间隙',
    symbol: '',
    unit: 'm',
    val: gapReel,
    bak: '两个卷筒之间的间隙'
  },

  { item: '价格计算' },

  {
    item: '钢丝绳单价',
    symbol: 'r_{gear}',
    unit: '元/t',
    val: priceRope
  },
  {
    item: '钢丝绳总价',
    symbol: 'r_{gear}',
    unit: '元',
    val: priceRopes
  },
  {
    item: '轴单价',
    symbol: 'r_{gear}',
    unit: '元/t',
    val: priceShaft
  },
  {
    item: '轴系总价',
    symbol: 'r_{gear}',
    unit: '元',
    val: priceShafts
  }

])
const window_height = window.innerHeight
const table_height = ref(10000)
const rowClassName = (row: rowType) => {
  if (sepRow.includes(row.item)) {
    return 'sep'
  } else {
    return ''
  }
}

const create3D = () => {
  /**
   * 如果父组件传入了创建3D模型的方法，则调用，否则控制台输出警告
   */
  if (props.create3D) {
    props.create3D()  //
  } else {
    console.warn('create3D not defined')
  }
}

const getColors = inject('getColors', () => {
  return {
    fgColor: '#000',
    bgColor: '#fff',
    buttonNormalColor: '#f8d7da',
    buttonHoverColor: '#90ee90'
  }
})

const { fgColor, bgColor, buttonNormalColor, buttonHoverColor } = getColors()

</script>

<template>
  <NConfigProvider>
    <!-- 使用NConfigProvider包裹一层，否则编辑器可能报警告[Vue warn]: injection "n-config-provider" not found.
at <DataTableBody ref="bodyInstRef" bodyStyle= {maxHeight: '10000px', minHeight: undefined} showHeader=false  ... > -->
    <div>
      <n-tag>方案3计算结果
        <button @click="create3D">生成3D模型</button>
        每组<input v-model="numGensPerGroup" type="number" name="number" style="width: 50px" />个电机
      </n-tag>
      <n-slider v-model:value="table_height" :min="200" :max="2000" :step="10" style="max-width: 100%" />
      <n-data-table :columns="columns()" :data="tableData" :pagination="false" :bordered="true"
        :max-height="table_height" :row-class-name="rowClassName" striped default-expand-all />

    </div>
  </NConfigProvider>
  <n-modal title="钢管混凝土参数" v-model:show="show_pillar_settings" preset="dialog">
    <n-form-item label="钢材材质">
      <n-flex vertical>
        <n-select v-model:value="pillar_set.steelType" :options="generateOptions(base_data.pillar.steelType)" />
      </n-flex>
    </n-form-item>
    <n-form-item label="混凝土型号">
      <n-flex vertical>
        <n-select v-model:value="pillar_set.concreteType" :options="generateOptions(base_data.pillar.concreteType)" />
      </n-flex>
    </n-form-item>
    <n-form-item label="含钢率">
      <n-flex vertical>
        <n-select v-model:value="pillar_set.steelRatio"
          :options="generateOptions(base_data.pillar.compressionStrength.alpha)" />
      </n-flex>
    </n-form-item>
    <n-form-item label="安全系数">
      <n-flex vertical>
        <n-input-number v-model:value="pillar_set.safetyFactor" placeholder=""></n-input-number>
      </n-flex>
    </n-form-item>
  </n-modal>
</template>

<style scoped>
.n-tag {
  border: coral;
  background-color: coral;
  width: 100%;
}

:deep(.n-data-table-th) {
  padding: 8px;
}

:deep(.n-data-table-td) {
  padding: 8px;
}

:deep(.sep td) {
  background-color: aqua !important;
}

:deep(div.n-input) {
  height: 30px;
  --n-height: 20px;
  padding: 0;
  margin: 0;
}

button {
  background-color: v-bind(buttonNormalColor);
  color: black;
  border: 0;
  padding: 3px 50px;
  margin: 100px;
  font-size: 16px;
  box-sizing: content-box;
  border-radius: 5px;
}

button:hover {
  background-color: v-bind(buttonHoverColor);
}
</style>
